﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class AssignmentParamElement : IdElement
    {
        private ExpressionElement expression;
        private RoundElement round1, round2;

        public ExpressionElement Expression { get { return expression; } set { expression = value; } }
        public RoundElement Round1 { get { return round1; } set { round1 = value; } }
        public RoundElement Round2 { get { return round2; } set { round2 = value; } }

        public AssignmentParamElement(TokenInfo StartInfo, TokenInfo Id, ExpressionElement Expression, RoundElement Round1, RoundElement Round2, List<TokenInfo> Comments)
            : base(Id, Comments)
        {
            startinfo = StartInfo;
            expression = Expression;
            round1 = Round1;
            round2 = Round2;
        }

        public override string ToString()
        {
            string result = string.Empty;
            if ((id != null) && (expression != null))
                result = string.Format("{0} := {1}", id, expression);
            else if (id != null)
                result = id.ToString();
            else result = expression.ToString();
            if (round1 != null)
                result += round1.ToString();
            if (round2 != null)
                result += round2.ToString();
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (expression != null)
                yield return expression;
            if (round1 != null)
                yield return round1;
            if (round2 != null)
                yield return round2;
        }
    }
}
